﻿
#region Copyright & License
// --------------------------
// Copyright 2008 Daniel Gray
// --------------------------
// This file is part of Kale.
//
// Kale is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Kale is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Kale.  If not, see <http://www.gnu.org/licenses/>.
#endregion
#region File details
// --------------------------------------------------------
// Filename          : SecurityBehavior.cs
// Author            : Daniel Gray
// Created           : 29/04/2008
// --------------------------------------------------------
#endregion
            
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;

namespace Kale.Web.Services.Behaviours
{
   public class SecurityBehavior : IEndpointBehavior
   {
      private string _cookieName;

      public SecurityBehavior(string cookieName)
      {
         _cookieName = cookieName;
      }

      #region IEndpointBehavior Members

      public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
      {
         return;
      }

      public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
      {
         throw new Exception("The SecurityDispatchMessageInspector is not used in client applications.");
      }

      public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
      {
         endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new SecurityDispatchMessageInspector(_cookieName));
      }

      public void Validate(ServiceEndpoint endpoint)
      {
         return;
      }

      #endregion
   }
}
